const mongoose = require("./db")

const messageSchema = mongoose.Schema(
    {
        // 嵌套对象包含一个text字段用于存储聊天信息
        message: {
            text: { type: String, required: true },
        },
        // 用于存储聊天双方标识(id)信息
        users: Array,

        sender: {
            // 为每个文档生成的唯一标识符
            type: mongoose.Schema.Types.ObjectId,
            ref: "user",
            required: true,
        },
    },
    {
        timestamps: true,
    }
);
let messageModel = mongoose.model('message', messageSchema, 'message')
module.exports = { messageModel }

